<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title th:replace="common/base::pagetitle"></title>
	<link th:replace="common/base::static"/>
	<link rel="stylesheet" th:href="@{/static/plugins/easyui/themes/material/easyui.css}">
	<link rel="stylesheet" th:href="@{/static/plugins/easyui/themes/icon.css}">
	<link rel="stylesheet" th:href="@{/static/css/wlb-treegrid.css}">
	</head>
<body style="background-color: #f2f2f2;">

<div id="credit">


	<div id="kPage" class="layui-fluid" style="padding: 0">
		<div class="layui-row">
			<!-- 主要内容块 -->
			<div class="layui-col-md12" id="kMainContentCol">
				<div class="layui-fluid wlb-fluid-padding15">
					<div class="layui-card">
						<form>
							<div class="layui-form layui-card-header wlb-card-header-auto">
								<div class="layui-form-item">
									<!--									<div class="layui-inline">-->
									<!--										<label class="layui-form-label">机构名称</label>-->
									<!--										<div class="layui-input-inline">-->
									<!--											<input type="text" name="compName" placeholder="请输入机构名称" autocomplete="off" class="layui-input">-->
									<!--										</div>-->
									<!--									</div>-->
									<div class="layui-inline">
										<button class="layui-btn " lay-submit="" lay-filter="kTableSearchFilter">
											<i class="layui-icon layui-icon-search"></i>
										</button>
										<button class="layui-btn " type="reset">
											<i class="layui-icon layui-icon-refresh-1"></i>
										</button>
									</div>
								</div>
							</div>
						</form>

						<div class="layui-card-body">
							<table id="kContentTable" lay-filter="kContentTable"></table>
						</div>
					</div>

				</div>
			</div>
		</div>
	</div>
</div>
<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>
<script th:src="@{/static/plugins/easyui/easyloader.js}"></script>

<script type="text/html" id="statusTpl">
	{{# if(d.status === '0') { }}
	<span class="layui-badge layui-bg-green">待处理</span>
	{{#  } else if(d.status === '1') { }}
	<span class="layui-badge layui-bg-orange">平台审核成功</span>
	{{#  } else if(d.status === '2') { }}
	<span class="layui-badge layui-bg-green">平台审核失败</span>
	{{#  } else if(d.status === '4') { }}
	<span class="layui-badge layui-bg-green">行内审核通过</span>
	{{#  } else if(d.status === '5') { }}
	<span class="layui-badge layui-bg-green">行内审核拒绝</span>
	{{# } else { }}
	<span class="layui-badge layui-bg-gray">其他</span>
	{{# } }}
</script>

<script type="text/html" id="tradeflagTpl">
	{{# if(d.tradeflag === true) { }}
	<span class="layui-badge layui-bg-green">有</span>
	{{# } else { }}
	<span class="layui-badge layui-bg-gray">无</span>
	{{# } }}
</script>



<!--头部工具栏模板-->
<!--<script type="text/html" id="headToolbarTpl">-->
<!--	<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>-->
<!--	<button class="layui-btn layui-btn-sm" lay-event="batchdel">删除</button>-->
<!--</script>-->


<!--表格行工具栏模板-->
<script type="text/html" id="rowToolbarTpl">
	<a class="layui-btn layui-btn-normal layui-btn-xs" data-event="edit" onclick="active.info(this)" data-id="{{d.id}}" data-supplierId="{{d.compId}}" data-status="{{d.status}}"><i class="layui-icon layui-icon-edit"></i>详情</a>
	{{# if(d.status == '0' && d.tradeflag === true) { }}
	<a class="layui-btn layui-bg-orange layui-btn-xs" data-event="audit" onclick="active.audit(this)" data-id="{{d.id}}" data-supplierId="{{d.compId}}" data-status="{{d.status}}"><i class="layui-icon layui-icon-form"></i>审核</a>
	{{#  } else { }}
	<a href="javascript:return false;"  style="opacity:0.3" class="layui-btn layui-bg-orange layui-btn-xs" data-event="audit" data-id="{{d.id}}" data-audiCompId="{{d.compId}}" data-status="{{d.status}}"><i class="layui-icon layui-icon-form"></i>审核</a>
	{{# } }}
	{{# if(d.tradeflag === true) { }}
	<a class="layui-btn layui-btn-xs" data-event="transaction" onclick="active.transaction(this)" data-compId="{{d.compId}}"><i class="layui-icon layui-icon-log"></i>交易记录</a>
	{{# } }}
</script>
<script type="text/javascript" th:inline="javascript">

	var active;
	layui.use(['element', 'form', 'layer', 'table', 'laytpl'], function () {
		var elemet = layui.element, form = layui.form, layer = layui.layer, table = layui.table;
		var tableId = 'kContentTable';

		// 实例化table
		var tableIns = table.render($.extend(config.layui.table, {
			elem: '#' + tableId
			, url: api.credit.creditListData //数据接口
			,response:{dataName: 'records',countName: 'total'}
			, toolbar: '#headToolbarTpl'
			, cols: [[ //表头
				{type: 'checkbox', fixed: 'left'}
				, {field: 'compName', title: '申请人', width: 200, fixed: false}
				, {field: 'bankName', title: '申请行', width: 200, fixed: false}
				, {field: 'createDate', title: '申请时间', width: 180, fixed: false}
				, {field: 'comCerNo', title: '工商注册号', width: 150, fixed: false}
				, {field: 'tradeflag', title: '交易历史状态', width: 80, templet: '#tradeflagTpl',fixed: false}
				// , {field: 'applyAmount', title: '申请授信额度', width: 150, fixed: false}
				, {field: 'status', title: '状态',  width: 130,align: 'center', templet: '#statusTpl',  fixed: false}
				, {field: '', title: '操作', width: 250, fixed: 'right', templet: '#rowToolbarTpl'}
			]]
		}));
		var area = ['450px', '530px'];

		// 监听表格头部事件
		table.on('toolbar(' + tableId + ')', function (obj) {
			var checkStatus = table.checkStatus(obj.config.id);
			var checkData = checkStatus.data; // 得到选中的数据
			switch (obj.event) {

				case 'auditInfo':
					layer.open({
						type: 2
						, title: '审核'
						, content: api.sys.creditAudit
						, maxmin: true
						, area: area   // 宽高
						, btn: ['确定', '取消']
						, yes: function (index, layero) {
							//点击确认触发 iframe 内容中的按钮提交
							var submit = layero.find('iframe').contents().find("#kFormSubmit");
							submit.click();
						}
					});
					break;
			}
		});


		// 监听事件
		active = {
			info: function (that) {
				var supplierId = $(that).data('supplierid');
				var auditId = $(that).data('id');
				// 1详情 2审核
				var type = 1;
				var status = $(that).data('status');
				var index = layer.open({
					type: 2
					, title: '详情'
					, content: api.credit.creditAuditView + "?supplierId=" + supplierId +"&type=" + type +"&auditId=" + auditId +"&status=" + status
					, maxmin: true
					, area: area   // 宽高
				});
				// layer.full(index);

			},

			audit: function (that) {
				var supplierId = $(that).data('supplierid');
				var auditId = $(that).data('id');
				var status = $(that).data('status');
				// 1详情 2审核
				var type = 2;
				var index = layer.open({
					type: 2
					, title: '审核'
					, content: api.credit.creditAuditView + "?supplierId=" + supplierId +"&type=" + type + "&auditId=" + auditId +"&status=" + status
					, maxmin: true
					, area: area   // 宽高
					, btn: ['确定', '取消']
					, yes: function (index, layero) {
						//点击确认触发 iframe 内容中的按钮提交
						var submit = layero.find('iframe').contents().find("#kFormSubmit");
						submit.click();
					}
				});
				// layer.full(index);

			},

			transaction: function (that) {
				var supplierId = $(that).data('compid');
				var area2 = ['80%', '80%'];
				var index = layer.open({
					type: 2
					, title: '交易记录'
					, content: api.credit.coreTradeView + "?supplierId=" + supplierId
					, maxmin: true
					, area: area2   // 宽高
				});
				// layer.full(index);
			},
		};

		wlbKit.activeInit(active);

		$(window).resize(function () {
			treeGridKit.fitRightFrozenCol(tableId);
		});

		// 列格式化函数
		var formatter = {
			rowToolbar: function (value, row, index) {
				return wlbKit.renderTpl('rowToolbarTpl', row);
			},
			status: function (value, row, index) {
				return wlbKit.renderTpl('statusTpl', row);
			},
			tradeflagTpl: function (value, row, index) {
				return wlbKit.renderTpl('tradeflagTpl', row);
			}
		};

		// 监听查询
		form.on('submit(kTableSearchFilter)', function (obj) {
			var params = obj.field;
			log('seach=', params); //

			tableIns.reload({
				where: params,
				page: {curr: 1}
			});
			return false;

		});

		// 绑定监听回车事件
		wlbKit.bindEnterEventForLayuiForm();

	});
</script>

</body>
</html>
